package com.xh.bussiness.system.controller;

import com.xh.bussiness.system.bean.dto.BusinessAttrConfigBean;
import com.xh.bussiness.system.bean.request.BusinessAttrConfigRequest;
import com.xh.bussiness.system.service.IBusinessAttrConfigService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags="业务属性配置接口")
/*
 * 业务流程接口
 * @Author daiwei
 * @Description
 * @Date 2019/2/14 08:53
 **/
@RestController
@RequestMapping("/system/ bussinessAttrConfig")
public class BusinessAttrConfigController extends BaseController {

    @Autowired
    private IBusinessAttrConfigService bussinessAttrConfigService;

    /**
     * 分页查询
     */
    @ApiOperation(value = "业务属性配置分页查询", notes = "业务属性配置分页查询")
    @PostMapping("/queryPage")
    public XhPage queryPage(XhPage page, BusinessAttrConfigRequest request) {
        return bussinessAttrConfigService.queryBusinessAttrConfigPage(page,request);
    }

    /**
     * 数据查询
     * @param request
     * @return
     */
    @ApiOperation(value="业务属性配置查询", notes = "业务属性配置查询")
    @PostMapping("/queryAll")
    public AjaxResult queryAll(BusinessAttrConfigRequest request) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "", bussinessAttrConfigService.queryBusinessAttrConfig(request));
    }


    /**
     * 新增和保存
     * @param businessAttrConfigBean 实体对象
     * @return
     */
    @ApiOperation(value="数据字典数据保存", notes = "数据字典数据保存")
    @PostMapping(value="/saveOrUpdate")
    @Transactional
    public AjaxResult saveOrUpdate(@Validated BusinessAttrConfigBean businessAttrConfigBean){
        if(businessAttrConfigBean.getId()==null){
            bussinessAttrConfigService.insertObj(businessAttrConfigBean);
        }else{
            bussinessAttrConfigService.updateObj(businessAttrConfigBean);
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"", businessAttrConfigBean);
    }

    /**
     * 删除操作
     * @param id
     * @return
     */
    @ApiOperation(value="业务属性配置删除", notes = "业务属性配置删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id", value="业务属性配置id", required = true, dataType = "String"),
    })
    @PostMapping("/deleteById")
    @Transactional
    public AjaxResult deleteById(String id){
        bussinessAttrConfigService.delete(id);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 批量删除操作
     * @param ids
     * @return
     */
    @ApiOperation(value="业务属性配置批量删除", notes = "业务属性配置批量删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="ids", value="业务属性配置id集合", required = true, dataType = "String[]"),
    })
    @PostMapping("/batchDelete")
    @Transactional
    public AjaxResult batchDelete(String[] ids){
        bussinessAttrConfigService.batchDelete(ids);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

}
